package gxb.test11;

abstract class Shape {
    //计算周长
    public abstract double calculatePerimeter();
    //计算面积
    public abstract double calculateArea();

}
class Rectangle extends Shape{
    private double length;
    private double width;

    public Rectangle(double length, double width) {
        this.length = length;
        this.width = width;
    }
    @Override
    public double calculatePerimeter() {
        return length * width;
    }
    @Override
    public double calculateArea() {
        return length * width;
    }
}
class Triangle extends Shape {
    private double side1;
    private double side2;
    private double side3;
    public Triangle(double side1, double side2, double side3) {
        this.side1 = side1;
        this.side2 = side2;
        this.side3 = side3;
    }

    public double calculatePerimeter() {
        return side1 + side2 + side3;
    }
    public double calculateArea() {
        //海伦公式：area=√(s*(s-a)(s-b)(s-c))
        double s = (side1 + side2 + side3) / 2;
        return Math.sqrt(s * (s - side1) * (s - side2) * (s - side3));
    }
}
class Circle1 extends Shape {
    private double radius;

    public Circle1(double radius) {
        this.radius = radius;
    }

    public double calculatePerimeter() {
        return 2 * Math.PI * radius;
    }

    public double calculateArea() {
        return Math.PI * radius * radius;
    }
}
public class ShapeTest{
    public static void main(String[] args) {
        Rectangle rectangle = new Rectangle(5, 3);
        System.out.println("Rectangle area: " + rectangle.calculateArea());
        System.out.println("Rectangle perimeter: " + rectangle.calculatePerimeter());

        Triangle triangle = new Triangle(3, 4, 5);
        System.out.println("Triangle area: " + triangle.calculateArea());
        System.out.println("Triangle perimeter: " + triangle.calculatePerimeter());

        Circle1 Circle1 = new Circle1(4);
        System.out.println("Circle1 area: " + Circle1.calculateArea());
        System.out.println("Circle1 perimeter: " + Circle1.calculatePerimeter());
    }
}
